#define DEBUG
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=100000, mods=1000000000;

class Point {
public:
  int x, y;

  static bool cmp(Point a, Point b) {
    return a.x<b.x || (a.x==b.x && a.y<b.y);
  }
};

typedef Point Side;

class Tree {
public:
  int n, m, ind[maxn+1], link[2*maxn-1], to[2*maxn-1], size[maxn+1], cnt[maxn+1];

  void init(int n) {
    this->n = n, m=0;
    for (int i=1; i<=n; i++) {
      ind[i] = cnt[i] = 0;
    }
  }

  void addSide(int u, int v) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
  }

  int build(int o, int fa) {
    size[o] = cnt[o];
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
	size[o] = (size[o]+build(to[i], o))%mods;
      }
    }
    return size[o];
  }

  long long solve(int o, int fa) {
    long long ret=0;
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
	ret = ((ret+solve(to[i], o))%mods+(long long)size[to[i]]*(cnt[0]-size[to[i]])%mods)%mods;
      }
    }
    return ret;
  }
};

int connect(int n, Point city[maxn+1]) {
  static Tree tree;
  static Side side[4*maxn+1];
  static int tonode[maxn+1];
  int i=1, j=1, sidesize=0;
  tree.init(n);
  tree.n = 0, tree.cnt[0]=n;
  for (; i<=n && city[i].x==city[j].x; i++) {
    if (city[i].x!=city[i-1].x || city[i].y!=city[i-1].y+1) {
      tree.n++;
    }
    tree.cnt[tree.n]++;
    tonode[i] = tree.n;
  }
  for (; i<=n; i++) {
    if (city[i].x!=city[i-1].x || city[i].y!=city[i-1].y+1) {
      tree.n++;
    }
    tree.cnt[tree.n]++;
    tonode[i] = tree.n;
    for (; j<=n && (city[j].x<city[i].x-1 || (city[j].x==city[i].x-1 && city[j].y<city[i].y)); j++);
    if (city[j].x==city[i].x-1 && city[j].y==city[i].y) {
      side[++sidesize].x = tonode[j];
      side[sidesize].y = tonode[i];
    }
  }

  sort(side+1, side+sidesize+1, Side::cmp);

  for (int i=1; i<=sidesize; i++) {
    if (side[i].x!=side[i-1].x || side[i].y!=side[i-1].y) {
      tree.addSide(side[i].x, side[i].y);
      tree.addSide(side[i].y, side[i].x);
    }
  }
  tree.build(1, 0);
  return tree.solve(1, 0);
}

int main() {
  freopen("city.in", "r", stdin);
  freopen("city.out", "w", stdout);

  Point city[maxn+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d %d", &city[i].x, &city[i].y);
  }

  sort(city+1, city+n+1, Point::cmp);
  long long ans=connect(n, city);

  for (int i=1; i<=n; i++) {
    int t;
    t=city[i].x, city[i].x=city[i].y, city[i].y=t;
  }
  sort(city+1, city+n+1, Point::cmp);
  ans += connect(n, city);

  printf("%lld", ans%mods);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
